home *** CD-ROM | disk | FTP | other *** search
- #
- # process the order from the user
- # process order title
- $TITLE="Order";
- ###############################
- # END OF CHANGEABLE OPTIONS #
- ###############################
-
- # START MAIN PROGRAM
- # ------------------
-
- &ReadParse;
- $Session = $in{'SessionID'};
- if ($Session eq '') {&PrintError; exit 1;} # An Error
- elsif ($Session eq '*SeSiOnId*') {&PrintError; exit 1;}; # Get a session id
-
- ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
- $mon = $mon + 1;
-
- # $date=`date '+%m%d%y'`;
- $date = $mon . $mday . $year;
-
- if (-e $date . ".ord") {
- if (!open(ORDFILE, ">>" . $date . ".ord")) { &PrintError; exit 1; };
- } else {
- if (!open(ORDFILE, ">" . $date . ".ord")) { &PrintError; exit 1; };
- }
-
- print ORDFILE "$Session\n"; # needed for utilities
- close(ORDFILE);
-
- if (!open(ORDER, ">" . $Session . ".frm")) { &PrintError; exit 1; };
-
- if (!dbmopen(%items, "$Session", 0777)) {
- &PrintError;
- exit 1;
- }
-
- if (!dbmopen(%prices, "prices", 0777)) {
- &PrintError;
- exit 1;
- }
-
- if ($items{'TotalOrder'} == 0) {
- &PrintNothingOrdered;
- exit 1;
- }
-
- print "Content-Type: text/html\n\n";
- print "<html><head><title>$Title</title></head><body BGCOLOR=#ffffff>";
-
- &printBoth("Order ID $Session", "<h1>", "</h1>");
- &printBoth("Date : $mon/$mday/$year, Time : $hour:$min", "<br>", "<br>");
- print ORDER "\n";
- &printBoth("Thank you for your order, here is a copy of the order that was processed", "<br>", "<br>");
- print ORDER "\n";
- &printCompany; # generated by CatMake
- print ORDER "\n";
- &printBoth("Please send me the following products :", "<br>", "");
- &printProducts; # will be generated by catmake
- &printShippingCharges;
- &printPaymentCharges;
- &printGrandTotal;
- &printPayment;
- &printBoth("Shipping information", "<br><B>", "</B>");
- &printShipping; # we got that info
- &printBoth("Billing information", "<br><B>", "</B>");
- &printBilling; # we got that info
- &printContact;
- &printComments;
-
- close(ORDER);
-
- dbmclose(%items);
- dbmclose(%prices);
-
- &PrintContinue; # The generator will make that
-
- exit(1);
-
- # GENERAL SUBROUTINES
- # -------------------
-
- sub ReadParse {
- local (*in) = @_ if @_; local ($i, $loc, $key, $val);
- if ($ENV{'REQUEST_METHOD'} eq "GET") { $in = $ENV{'QUERY_STRING'}; }
- elsif ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN,$in,$ENV{'CONTENT_LENGTH'}); }
- @in = split(/&/,$in);
- foreach $i (0 .. $#in) {
- $in[$i] =~ s/\+/ /g;
- ($key, $val) = split(/=/,$in[$i],2); # splits on the first =.
- $key =~ s/%(..)/pack("c",hex($1))/ge;
- $val =~ s/%(..)/pack("c",hex($1))/ge;
- $in{$key} .= "\0" if (defined($in{$key})); # \0 is the multiple separator
- $in{$key} .= $val;
- }
- return 1; # just for fun
- } # ReadParse
-
- sub PrintError {
- print("Content-Type: text/html\n\n");
- print <<EOF;
- <HTML>
- <HEAD><TITLE>ERROR</TITLE></HEAD>
- <BODY>
- <H1 ALIGN=CENTER>$TITLE</H1> <HR>
- An error occured in the script!
- <HR>
- EOF
- } # PrintError
-
- sub printBoth {
- local ($message, $before, $after) = @_;
- print ORDER $message . "\n";
- print $before . $message . $after;
- } # printBoth
-
- sub printShipping {
- &printBoth($in{'SHIPNAME'}, "<br>", "");
- &printBoth($in{'SHIPTITLE'}, "<br>", "");
- &printBoth($in{'SHIPCOMPANY'}, "<br>", "");
- &printBoth($in{'SHIPADDR1'}, "<br>", "");
- &printBoth($in{'SHIPADDR2'}, "<br>", "");
- &printBoth($in{'SHIPCITY'}, "<br>", "");
- &printBoth($in{'SHIPSTATE'}, "<br>", "");
- &printBoth($in{'SHIPZIP'}, "<br>", "");
- &printBoth($in{'SHIPCOUNTRY'}, "<br>", "");
- } # printShipping
-
- sub printBilling {
- if ($in{'BILLNAME'} eq '') {
- &printBoth("Same as shipping", "<br>", "<br>");
- } else {
- &printBoth($in{'BILLNAME'}, "<br>", "");
- &printBoth($in{'BILLTITLE'}, "<br>", "");
- &printBoth($in{'BILLCOMPANY'}, "<br>", "");
- &printBoth($in{'BILLADDR1'}, "<br>", "");
- &printBoth($in{'BILLADDR2'}, "<br>", "");
- &printBoth($in{'BILLCITY'}, "<br>", "");
- &printBoth($in{'BILLSTATE'}, "<br>", "");
- &printBoth($in{'BILLZIP'}, "<br>", "");
- &printBoth($in{'BILLCOUNTRY'}, "<br>", "");
- }
- } # printBilling
-
- sub printContact {
- &printBoth("Contact Information", "<B>", "</B>");
- &printBoth("Tel : " . $in{'PHONE'}, "<br>", "");
- &printBoth("Fax : " . $in{'FAX'}, "<br>", "");
- &printBoth("EMail1 : " . $in{'EMAIL1'}, "<br>", "");
- &printBoth("EMail2 : " . $in{'EMAIL2'}, "<br>", "");
- } # printContact
-
- sub printShippingCharges {
- &printBoth("Shipping Charges", "<br><b>", "</b>");
- $Shipping = "S_" . $in{'SHIPOPT'};
- $TotalShipping = ($prices{$Shipping . "3"} * $items{'TotalProducts'}) +
- $prices{$Shipping . "1"} + ($prices{$Shipping . "2"} * $items{'TotalWeight'});
- &printBoth("Total for $in{'SHIPOPT'} : \$$TotalShipping", "<br>", "<br>");
- } # printShippinhCharges
-
- sub printPayment {
- &printBoth("Payment Method", "<br><b>", "</b>");
- &printBoth("Payment by $in{'PAYOPT'}", "<br>", "");
- if ($prices{$payment . "1"} == 1) {
- # Purchase Orders
- &printBoth("PO/WT number $in{'CARDNUM'}", "<br>", "");
- } elsif ($prices{$payment . "1"} == 2) {
- # Credit Card
- &printBoth("Card number : $in{'CARDNUM'}", "<br>", "");
- &printBoth("Name on card : $in{'NAMEONCARD'}", "<br>", "");
- &printBoth("Expiration date : $in{'EXPRDATE'}", "<br>", "");
- }
- } # printPayment
-
- sub printPaymentCharges {
- $payment = "P_" . $in{'PAYOPT'};
- $fee = $prices{$payment . "2"};
- if ($fee != 0) {
- &printBoth("Payment fee is \$$fee", "<br>", "<br>");
- } # there are payment fees
- } # printPaymentCharges
-
- sub printGrandTotal {
- $GrandTotal = $fee + $items{'TotalOrder'} + $TotalShipping;
- &printBoth("Total payment is \$$GrandTotal", "<br>", "<br>");
- } # printGrandTotal
-
- sub printComments {
- if (!($in{'COMMENTS'} eq '')) {
- &printBoth("Comments", "<br><b>", "</b>");
- &printBoth($in{'COMMENTS'}, "<br>", "");
- }
- } # printComments
-
- sub PrintNothingOrdered {
- print("Content-Type: text/html\n\n");
- print <<EOF;
- <HTML>
- <HEAD><TITLE>Order Error</TITLE></HEAD>
- <BODY BGCOLOR=#ffffff>
- <H1 ALIGN=CENTER>Order Error</H1><HR>
- No products were ordered!<br>
- Please press the Back button, specify what products you want to
- order by clicking the Submit button under an item's quantity table,
- after you have specified the number of items in the table!
- <HR>
- EOF
- } # PrintNothingOrdered
-
-